

cc.Class({
    extends: cc.Component,

    properties: {
        bulletPre: cc.Prefab,
        bulletDtJson: cc.JsonAsset,
    },



    onLoad() {
    },

    start() {

    },

    // update (dt) {},
    createBullet(pos, owner, type) {
        //实例化一个子弹
        let bulletNode = cc.instantiate(this.bulletPre);
        bulletNode.parent = this.node;
        bulletNode.position = pos;
        //根据发射子弹的对象设置子弹的图片的方向
        if (owner == "player") {
            bulletNode.scaleY *= 1;
        }
        else if (owner == "enemy") {
            bulletNode.scaleY *= -1;
        } else if (owner == "pet") {
            bulletNode.scaleY *= 1;
        }
        let index = 0;
        for (let i = 0; i < this.bulletDtJson.json.length; i++) {
            if (type == this.bulletDtJson.json[i].type) {
                index = i;
            }
        }
        let bulletJs = bulletNode.getComponent("Bullet");
        let bulletDt = this.bulletDtJson.json[index];
        //设置子弹的精灵帧
        bulletJs.initSpriteFrame(bulletDt);
        //设置子弹的移动
        bulletJs.bulletMove(owner);

    }
});
